#include"stdio.h"
extern int flag=1;

void my_wc(int res_current[],char c);
void excute(char file_name[]);

int main() {
    char file_name[] = "test.txt";
    excute(file_name);
    return 0;
}

void excute(char file_name[]){
	FILE *fp;
    printf("%s\n", file_name);
    char c;
	int i,j;
    int res_current[3];
    int res_total[3];

    for(i=0;i<3;i++)
    {
            res_current[i]=0;
            res_total[i]=res_current[i];
        }
       j=0;
      // printf("%s\n", file_name);
        while(++j<2)
        {
                    printf("*\n");
                        if((fp=fopen(file_name,"r"))==NULL)
                        {
                            printf("Can not open the file %s\n",file_name);
                            exit(0);
                        }
                        //printf("%s\n", file_name);
                        c=fgetc(fp);
                        while(c!=EOF)
                        {
                            my_wc(res_current,c);
                            //printf("%s\n", file_name);
                            c=fgetc(fp);
                            //printf("%s\n", file_name);

                        }
                        fclose(fp);
                        //printf("%s\n", file_name);
                        printf(" %d  %d %d %s\n",res_current[0],res_current[1],res_current[2],file_name);
                        for(i=0;i<3;i++)
                        {
                                res_total[i]+=res_current[i];
                                res_current[i]=0;
                        }
                }
                printf(" %d %d %d total\n",res_total[0],res_total[1],res_total[2]);

}

void my_wc(int res_current[],char c)
{
    //printf("****\n");
        int flag;
        res_current[2]++;
        if(c=='\n')
        {
            res_current[0]++;
        }
        if(c=='\t' || c== ' ' || c=='\n')
        {
                if(flag==0)
                {
                        res_current[1]++;
                        //printf("%d\n", res_current[1]);
                         flag=1;
                }
        }
        else
        flag=0;
}
